#include<iostream>
#include<string>
using namespace std;

class Shape {
public:
    Shape();
    Shape(string color, bool filled);
    ~Shape();

    string get_color();
    void set_color(string color);
    bool is_filled();
    void set_filled(bool filled);

    virtual float get_area() = 0;

private:
    string color;
    bool filled;
};

Shape::Shape() {}

Shape::Shape(string color, bool filled) {
    this->color = color;
    this->filled = filled;
}

Shape::~Shape() {}

string Shape::get_color() {
    return color;
}

void Shape::set_color(string color) {
    this->color = color;
}

bool Shape::is_filled() {
    return filled;
}

void Shape::set_filled(bool filled) {
    this->filled = filled;
}

class Circle : public Shape {
public:
    Circle();
    Circle(string color, bool filled, float radius);
    ~Circle();

    float get_radius();
    void set_radius(float radius);
    float get_area() override;

private:
    float radius;
};

Circle::Circle() {}

Circle::Circle(string color, bool filled, float radius) : Shape(color, filled) {
    this->radius = radius;
}

Circle::~Circle() {}

float Circle::get_radius() {
    return radius;
}

void Circle::set_radius(float radius) {
    this->radius = radius;
}

float Circle::get_area() {
    cout << "园形面积为：" << this->radius * this->radius * 3.14159;
    return 3.14159 * radius * radius;
}

class Rectangle : public Shape {
public:
    Rectangle();
    Rectangle(string color, bool filled, float length, float width);
    ~Rectangle();

    float get_length();
    void set_length(float length);
    float get_width();
    void set_width(float width);
    float get_area();

private:
    float length;
    float width;
};

Rectangle::Rectangle() {}

Rectangle::Rectangle(string color, bool filled, float length, float width) : Shape(color, filled) {
    this->length = length;
    this->width = width;
}

Rectangle::~Rectangle() {}

float Rectangle::get_length() {
    return length;
}

void Rectangle::set_length(float length) {
    this->length = length;
}

float Rectangle::get_width() {
    return width;
}

void Rectangle::set_width(float width) {
    this->width = width;
}

float Rectangle::get_area() {
    cout << "长方形面积为：" << this->length*this->width;
    return length * width;
}

class Square : public Shape {
public:
    Square();
    Square(string color, bool filled, float side);
    ~Square();

    float get_side();
    void set_side(float side);
    float get_area() override;

private:
    float side;
};

Square::Square() {}

Square::Square(string color, bool filled, float side) : Shape(color, filled) {
    this->side = side;
}

Square::~Square() {}

float Square::get_side() {
    return side;
}

void Square::set_side(float side) {
    this->side = side;
}

float Square::get_area() {
    cout << "正方形面积为：" <<this->side*this->side;
    return side * side;
}
void operate(Shape *p){
    cout<<p->get_area()<<endl;
}
int main() {
    
    Circle *circle=new Circle("红色", true, 2.3);
    Rectangle *rectangle=new Rectangle("黄色", false, 5, 10);
    Square *square=new Square("黄色", true, 3);

    operate(circle);
    operate(rectangle);
    operate(square);
    // 注意，在使用动态分配u空间后，一定要记住释放动态申请的内存，以防发生内存泄漏的问题。
    delete circle;
    delete rectangle;
    delete square;

    return 0;
}